const app = getApp()
const publicFun = require('/utils/public.js')
Component({
  data: {
    selected: 0,
    tabBar: {
      textColor: "#000",
      selectedColor: "#000",
      items: [
        {
          "pagePath": "/pages/index/index",
          "name": "首页",
          "icon": "/images/tabber/icon_checkIn_normal.png",
          "activeIcon": "/images/tabber/icon_checkIn_select.png"
        },
        {
          "pagePath": "/pages/cardList/cardList",
          "name": "",
          "icon": "/images/tabber/icon_release.png",
          "activeIcon": "/images/tabber/icon_release.png"
        },
        {
          "pagePath": "/pages/my/my",
          "name": "我的",
          "icon": "/images/tabber/icon_my_normal.png",
          "activeIcon": "/images/tabber/icon_my_select.png"
        }
      ]
    }
  },
  methods: {
    switchTab(e) {
      const {dataset: { item: { pagePath = '' }} = {}} = e.currentTarget
      let data = e.currentTarget.dataset;
      if(data.index == 1){
        if(app.globalData.userid){
          my.navigateTo({
            url: pagePath
          })
        }else{
          publicFun.jumpLogin();
        }
      }else{
        my.switchTab({
          url: pagePath,
          success: ()=> {
            my.pageScrollTo({ scrollTop: 0, duration: 1500 });
          }
        })
      }
      
    }
  }
});
